package com.tange.ai.core.sample.assistance

import android.Manifest
import android.content.Intent
import android.content.pm.PackageManager
import android.graphics.Color
import android.os.Build
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.core.app.ActivityCompat
import com.tange.ai.core.sample.binding.BindingWaysActivity
import com.tange.ai.core.sample.utils.Utils
import com.tange.ai.core.sample.databinding.ActivityAddTypeChooseBinding
import com.tange.ai.core.sample.databinding.ActivityDevelopmentAssistanceBinding
import com.tange.base.toolkit.onClicked
import com.tange.base.toolkit.paddingStatusBar
import com.tange.base.ui.design.BasicDialogLoading
import com.tange.base.ui.design.BasicDialogRequest
import com.tange.core.trouble.shooting.logging.RuntimeLogging
import com.tange.core.trouble.shooting.qrcode.DebuggingQrcode

class DevelopmentAssistanceActivity: AppCompatActivity() {

    private lateinit var binding: ActivityDevelopmentAssistanceBinding

    private lateinit var loading: BasicDialogLoading

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        binding = ActivityDevelopmentAssistanceBinding.inflate(layoutInflater).apply {
            setContentView(root)
            supportActionBar?.hide()
            root.paddingStatusBar()
        }

        Utils.setStatusBar(this, Color.TRANSPARENT)

        binding.top.left.onClicked { finish() }

        loading = BasicDialogLoading(this).apply {
            setMessage("上传中...")
        }


        binding.loggingUpload.onClicked {

            loading.dismiss()
            loading.show()

            RuntimeLogging.upload {

                loading.dismiss()

                val tips = if (it.success) "成功，日志编号：${it.data}" else "上传错误：${it.code}, ${it.message}"

                BasicDialogRequest(this@DevelopmentAssistanceActivity).apply {
                    setMessage(tips)
                    setPositiveText("好的")
                    setPositiveOnClicked {
                        finish()
                        dismiss()
                    }
                }.show()
            }
        }

        binding.debuggingQrcode.onClicked { DebuggingQrcode.create(it.context) }
    }
}